package com.example.pertecttime.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.pertecttime.R;

import java.util.LinkedList;
import java.util.Map;

/**
 * Created by 半生瓜 on 2017/8/1.
 */

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
    private LinkedList<Map<String, Object>> list;
    public MyAdapter(LinkedList<Map<String, Object>> list) {
        this.list = list;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = View.inflate(viewGroup.getContext(), R.layout.list_item, null);
        return new ViewHolder(view);
    }
    //在控件中绑定数据
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int i) {
        viewHolder.title_tv.setText(list.get(i).get("title").toString());
        viewHolder.content_tv.setText(list.get(i).get("content").toString());
        viewHolder.face.setImageResource((int)list.get(i).get("face"));
    }
    @Override
    public int getItemCount() { return list.size(); }
    //将控件与ViewHolder进行绑定
    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView title_tv;
        public TextView content_tv;
        public ImageView face;
        public ViewHolder(View itemView) {
            super(itemView);
            title_tv = (TextView) itemView.findViewById(R.id.item_title_tv);
            content_tv = (TextView)
                    itemView.findViewById(R.id.item_content_tv);
            face = (ImageView) itemView.findViewById(R.id.face);
        }
    }
}

